package com.redijedi.tapestry.internal;

import org.apache.tapestry.ValueEncoder;

/**
 * @author torr
 * 
 */
public class GenericValueEncoder implements ValueEncoder<Object> {

	private final Iterable<?> _source;

	public GenericValueEncoder(Iterable<?> source) {
		_source = source;
	}

	public String toClient(Object value) {
		return value == null ? "" : value.toString();
	}

	public Object toValue(String clientValue) {
		for (Object o : _source) {
			if (o.toString() == clientValue) {
				return o;
			}
		}
		return null;
	}

}
